package com.addcn.caruimodule.text

import android.content.Context
import android.content.res.TypedArray
import android.graphics.Canvas
import android.graphics.Paint
import android.text.TextPaint
import android.util.AttributeSet

import androidx.appcompat.widget.AppCompatTextView

import com.addcn.caruimodule.R


/**
 * author:luwenbo
 * created on date : 2019-10-29
 * content:
 * describe:
 */
class MediumBoldTextView : AppCompatTextView {
    private var mediumWidth = 0.9f

    constructor(context: Context) : super(context) {}

    constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
        initAttrs(context, attrs)
    }

    constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    ) {
        initAttrs(context, attrs)
    }

    private fun initAttrs(context: Context, attrs: AttributeSet?) {
        if (attrs != null) {
            val attributeArray =
                context.obtainStyledAttributes(attrs, R.styleable.MediumBoldTextView)
            mediumWidth =
                attributeArray.getFloat(R.styleable.MediumBoldTextView_mediumSize, mediumWidth)
        }

    }


    fun setMediumWidth(mediumWidth: Float) {
        this.mediumWidth = mediumWidth
    }

    override fun onDraw(canvas: Canvas) {
        //获取当前控件的画笔
        val paint = paint
        //设置画笔的描边宽度值
        paint.strokeWidth = mediumWidth
        paint.style = Paint.Style.FILL_AND_STROKE
        super.onDraw(canvas)

    }
}
